home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / bbs_util / bsrc_260.zip / SRC.ZIP / SQUISH.C < prev    next >
C/C++ Source or Header  |  1996-02-20  |  5KB  |  142 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*              (C) Copyright 1987-96, Bit Bucket Software Co.              */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*                                                                          */
  14. /*                     Squish scan for unread mail                          */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*    For complete  details  of the licensing restrictions, please refer    */
  18. /*    to the License  agreement,  which  is published in its entirety in    */
  19. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.260.    */
  20. /*                                                                          */
  21. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  22. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  23. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  24. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  25. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  26. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  27. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  28. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  29. /*                                                                          */
  30. /*                                                                          */
  31. /* You can contact Bit Bucket Software Co. at any one of the following      */
  32. /* addresses:                                                               */
  33. /*                                                                          */
  34. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  35. /* P.O. Box 460398                AlterNet 7:42/1491                        */
  36. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  37. /*                                Internet f491.n343.z1.fidonet.org         */
  38. /*                                                                          */
  39. /* Please feel free to contact us at any time to share your comments about  */
  40. /* our software and/or licensing policies.                                  */
  41. /*                                                                          */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. /* Include this file before any other includes or defines! */
  45.  
  46. #include "includes.h"
  47.  
  48. #include "squish.h"
  49.  
  50. #define OPEN_FLAGS          O_RDWR | O_BINARY
  51. #define SHARE_FLAGS         SH_DENYNO
  52. #define PERMISSION_FLAGS    S_IREAD | S_IWRITE
  53. #define MSG_RDLEN           sizeof(XMSG) + sqbase.sz_sqhdr
  54.  
  55. typedef struct
  56. {
  57.     SQHDR sqhdr;
  58.     XMSG xmsg;
  59. } SQMSG;
  60.  
  61. static int SquishOpen (char *, PSQBASE);
  62.  
  63. int 
  64. SquishScan (char *pszName)
  65. {
  66.     int fh;
  67.     int unread;
  68.     FOFS fofs;
  69.     SQBASE sqbase;
  70.     SQMSG sqmsg;
  71.     char szSqd[256];
  72.  
  73.     strcpy (szSqd, pszName);
  74.     strcat (szSqd, ".SQD");
  75.  
  76.     if ((fh = SquishOpen (szSqd, &sqbase)) < 0)
  77.     {
  78.         status_line (MSG_TXT (M_SQUISH_OPENERR), szSqd);
  79.         return 0;
  80.     }
  81.  
  82.     fofs = sqbase.begin_frame;
  83.     unread = 0;
  84.  
  85.     while (fofs)
  86.     {
  87.         if ((lseek (fh, fofs, SEEK_SET)) != (long)fofs)
  88.         {
  89.             close (fh);
  90.             status_line (MSG_TXT (M_SQUISH_SEEKERR), szSqd);
  91.             return 0;
  92.         }
  93.  
  94.         if ((read (fh, &sqmsg, MSG_RDLEN)) < (int)MSG_RDLEN)
  95.         {
  96.             close (fh);
  97.             status_line (MSG_TXT (M_SQUISH_READERR), szSqd);
  98.             return 0;
  99.         }
  100.  
  101.         if (sqmsg.sqhdr.id != (dword) SQHDRID)
  102.         {
  103.             close (fh);
  104.             status_line (MSG_TXT (M_SQUISH_TRASHED_HDR), szSqd);
  105.             return 0;
  106.         }
  107.  
  108.         if (sqmsg.sqhdr.frame_type == FRAME_NORMAL)
  109.         {
  110.             if (!(sqmsg.xmsg.attr & MSGREAD))
  111.             {
  112.                 unread++;
  113.             }
  114.  
  115.             fofs = sqmsg.sqhdr.next_frame;
  116.         }
  117.     }
  118.  
  119.     close (fh);
  120.     return unread;
  121. }
  122.  
  123. static int 
  124. SquishOpen (char *pszName, PSQBASE psqbase)
  125. {
  126.     int fh;
  127.  
  128.     if ((fh = sopen (pszName,
  129.                 OPEN_FLAGS,
  130.                 SHARE_FLAGS,
  131.                 PERMISSION_FLAGS)) != -1)
  132.     {
  133.         if ((read (fh, psqbase, sizeof (SQBASE))) < sizeof (SQBASE))
  134.         {
  135.             close (fh);
  136.             fh = -1;
  137.         }
  138.     }
  139.  
  140.     return fh;
  141. }
  142.